package satir.cell;

/**
 * The Class Cell.
 * @version 3.0 April 2012
 * @author Creative Family
 */
public class Cell {

    /** The width. */
    protected int width;

    /** The height. */
    protected int height;

    /** The array for display. */
    protected char[][] cellGround;

    /** The border horizontal. */
    private char borderHorizontal;

    /** The border vertical. */
    private char borderVertical;

    /** The cell label. */
    protected String cellLabel;

    /**
     * Instantiates a new cell.
     * @param width
     *            the width
     * @param height
     *            the height
     * @param borderHorizontal
     *            the border horizontal
     * @param borderVertical
     *            the border vertical
     * @param cellLabel
     *            the cell label
     */
    public Cell(final int width, final int height, final char borderHorizontal,
	    final char borderVertical, final String cellLabel) {
	this.width = width;
	this.height = height;
	this.borderHorizontal = borderHorizontal;
	this.borderVertical = borderVertical;
	this.cellGround = new char[height][width];
	this.cellLabel = cellLabel;
	// Fill in the array for display
	for (int i = 0; i < height; i++) {
	    for (int j = 0; j < width; j++) {
		if (i == 0 || i == height - 1) {
		    this.cellGround[i][j] = this.borderHorizontal;
		} else if (j == 0 || j == width - 1) {
		    this.cellGround[i][j] = this.borderVertical;
		} else if (i == height - 2) {
		    if (j > cellLabel.length()) {
			this.cellGround[i][j] = ' ';
		    } else {
			this.cellGround[i][j] = cellLabel.charAt(j - 1);
		    }
		} else {
		    this.cellGround[i][j] = ' ';
		}
	    }
	}
    }

    /**
     * Gets the height.
     * @return the height
     */
    public int getHeight() {
	return height;
    }

    /**
     * Gets the width.
     * @return the width
     */
    public int getWidth() {
	return width;
    }

    /**
     * Display the cell according to the row number.
     * @param rowNum
     *            the row number
     */
    public void display(final int rowNum) {
	for (int i = 0; i < width; i++) {
	    System.out.print(cellGround[rowNum][i]);
	}
    }
}
